/************************************************************
Copyright (C), 2017-2040, Wizzy-phone 
FileName: i2c.h
Author:	Linhao
Version :
Date:	2017.12.19
Description:  set i2c function , Using analog I2C
Version:	V1.0 
Function List:
History: 
***********************************************************/

#ifndef __I2C_H_
#define __I2C_H_




#include "stm8l15x_gpio.h"
#include "stm8l15x_i2c.h"





//#define _DEBUG_

#ifdef _DEBUG_
#include "uart.h"
#endif


#define BUFFERSIZE 						(16)




#define	SlaveAddress	                (0x10)
#define Register_Address 				(0x80)
#define IIC_SDA_GPIO_Pin                GPIO_Pin_0			
#define IIC_SCL_GPIO_Pin                GPIO_Pin_1
#define IIC_GPIOx                       GPIOC


#define SET_PORT_SDA_HIGH()	 (GPIO_Init((IIC_GPIOx), (IIC_SDA_GPIO_Pin), (GPIO_Mode_Out_PP_High_Fast)))
#define SET_PORT_SDA_LOW()	 (GPIO_Init((IIC_GPIOx), (IIC_SDA_GPIO_Pin), (GPIO_Mode_Out_PP_Low_Fast)))
#define SET_PORT_SCLK_HIGH() (GPIO_Init((IIC_GPIOx), (IIC_SCL_GPIO_Pin), (GPIO_Mode_Out_PP_High_Fast)))
#define SET_PORT_SCLK_LOW() (GPIO_Init((IIC_GPIOx), (IIC_SCL_GPIO_Pin), (GPIO_Mode_Out_PP_Low_Fast)))





#define TP_L 	0x1A
#define TP_R 	0x1B
#define TP_U	0x1C
#define TP_D	0x1D
#define TP_C	0x1E




void Delay(void);
void I2C_init(void);
int SDA_Read_Ack(void);
void IIC_Start(void);
void IIC_Stop(void); 
u8 IIC_Wait_Ack(void);
void IIC_Ack(void);
void IIC_NAck(void);
void IIC_Send_Byte(u8 txd);
u8 IIC_Read_Byte(u8 ack);
u8 I2C_write_reg(u8 *pBuffer,u8 WriteAddr,u8 NumToWrite);
u8 I2C_read_reg(u8 *pBuffer,u8 WriteAddr,u8 NumToRead);
u8 I2C_write(u8 WriteAddr,u8 pBuffer);
void I2C_Write_Tp(void);
void I2C_Tp_Switch_To_Mouse(void);

u8 I2C_Tp_Read(void);


#endif		//__I2C_H_
